home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: int (*p)[4]; (Watcom problem)
- Date: 10 Apr 1996 15:44:45 GMT
- Organization: Borland International
- Message-ID: <4kgl1d$6lm@druid.borland.com>
- References: <4kcd03$37j@morgoth.sfu.ca>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- Keywords: WATCOM C++ POINTER ARRAY PROBLEM
- X-Newsreader: WinVN 0.99.5
-
- In article <4kcd03$37j@morgoth.sfu.ca>, mpohores@news.sfu.ca says...
- >
- >I came across (ARM, page 97) the following way to define
- >a pointer to an array:
- > int (*p)[];
- >
- >(Yes, I allready know I can just do: int *p)
- >So I tried it in a small C++ test program: p2a.cpp
- >
- >#include <stdio.h>
- >
- >void main( void )
- >{
- > int a[4] = { -13, 11, -7, 5 };
- > int (*x)[4]; // pointer to array
- >
- > for (int i = 0; i < 4; i++ )
- > {
- > (int *)x = &a[i];
- > printf( "%d\n", (*x)[0] );
- > }
- >}
- >
- >Now here's my problem:
- > Under Watcom 10.5, the above doesn't compile with wcl386
- >but it compiles under DJGPP 2.0, and Borland C++ 3.1 Anyone know why?
- >
- > Is this a bug?
-
- Yes, your code has a serious bug. When you couldn't fit a round peg into a
- square hole you used a hammer to make it fit. Get rid of the (int *) cast in
- your assignment statement. Take the time to understand why it does not compile
- and fix the problem. Hint: a pointer to an int is not the same thing as a
- pointer to an array of ints.
-
-